<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="经办人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlerId">
              <a-input :disabled="formDisabled" v-model="model.handlerId" placeholder="请输入经办人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="经办部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlerDeptId">
              <a-input :disabled="formDisabled" v-model="model.handlerDeptId" placeholder="请输入经办部门"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date
                :disabled="formDisabled"
                placeholder="请选择创建时间"
                v-model="model.createTime"
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="用印公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userCompany">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.userCompany"
                dictCode=""
                placeholder="请选择用印公司"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyPreson">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.applyPreson"
                dictCode=""
                placeholder="请选择申请人"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyDept">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.applyDept"
                dictCode=""
                placeholder="请选择申请部门"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="用印类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sealType">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.sealType"
                dictCode=""
                placeholder="请选择用印类别"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="文件类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fileType">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.fileType"
                dictCode=""
                placeholder="请选择文件类别"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectType">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.projectType"
                dictCode=""
                placeholder="请选择项目类别"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractAmount">
              <a-input :disabled="formDisabled" v-model="model.contractAmount" placeholder="请输入合同金额"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否借出" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lendYn">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.lendYn"
                dictCode="yes_no"
                placeholder="请选择是否借出"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="用印日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userDate">
              <j-date :disabled="formDisabled" placeholder="请选择用印日期" v-model="model.userDate" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input :disabled="formDisabled" v-model="model.projectName" placeholder="请输入项目名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否关联任务" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relateTask">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="radio"
                v-model="model.relateTask"
                dictCode="yes_no"
                placeholder="请选择是否关联任务"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="生产团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productionTeam">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.productionTeam"
                dictCode=""
                placeholder="请选择生产团队"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessName">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.businessName"
                dictCode=""
                placeholder="请选择业务名称"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="业务分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessType">
              <j-dict-select-tag
                :disabled="formDisabled"
                type="list"
                v-model="model.businessType"
                dictCode=""
                placeholder="请选择业务分类"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="用印文件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useFile">
              <a-input :disabled="formDisabled" v-model="model.useFile" placeholder="请输入用印文件"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="份数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input-number
                :disabled="formDisabled"
                :max="99999999"
                :min="0"
                v-model="model.quantity"
                placeholder="请输入份数"
                style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="用印说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userExplain">
              <a-input :disabled="formDisabled" v-model="model.userExplain" placeholder="请输入用印说明"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="上传附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="upload">
              <j-upload :disabled="formDisabled" v-model="model.upload"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'
export default {
  name: 'ErpSealUsageInformationForm',
  components: {},
  props: {
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 }
      },
      confirmLoading: false,
      validatorRules: {
        userCompany: [
          { required: true, message: '请输入用印公司!' }
        ],
        sealType: [
          { required: true, message: '请输入用印类别!' }
        ],
        fileType: [
          { required: true, message: '请输入文件类别!' }
        ],
        projectType: [
          { required: true, message: '请输入项目类别!' }
        ],
        contractAmount: [
          { required: true, message: '请输入合同金额!' }
        ],
        lendYn: [
          { required: true, message: '请输入是否借出!' }
        ],
        relateTask: [
          { required: true, message: '请输入是否关联任务!' }
        ],
        useFile: [
          { required: true, message: '请输入用印文件!' }
        ],
        quantity: [
          { required: true, message: '请输入份数!' }
        ],
        upload: [
          { required: true, message: '请输入上传附件!' }
        ]
      },
      url: {
        add: '/api/erp/administration/seal/erpSealUsageInformation/add',
        edit: '/api/erp/administration/seal/erpSealUsageInformation/edit',
        queryById: '/api/erp/administration/seal/erpSealUsageInformation/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    // 备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }
      })
    }
  }
}
</script>
